
package com.hd.determine.modules.vehicle.utils;

import com.alibaba.fastjson.JSON;
import com.hd.common.utils.ValueUtils;
import com.hd.determine.config.redis.utils.JedisUtil;
import com.hd.determine.modules.alarm.model.AlarmRule;
import com.hd.determine.modules.vehicle.model.VehicleEndPos;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author chentl
 * @version V1.0
 * @Project 交通运输第三方监测平台
 * @Title VehicleUtils.java
 * @Description 车辆工具类
 * @Package com.hd.sup.modules.vehicle.utils
 * @date 2021/1/29 10:14 上午
 * @Copyright: 深圳市宏电技术股份有限公司 All rights reserved.
 */
@Slf4j
@Component
public class VehicleUtils {

    @Resource
    private JedisUtil jedisUtil;

    /**
     * @return java.lang.Object
     * @author chentl
     * @description 获取当前末次位置缓存中的对象
     * @date 2021/1/29 10:15 上午
     * @params []
     */
    public VehicleEndPos currentEndPosCache(String key) {
        Object result = jedisUtil.get(key, 0);
        return JSON.parseObject(result.toString(), VehicleEndPos.class);
    }

    /**
     * @return com.hd.sup.modules.alarm.model.AlarmRule
     * @author chentl
     * @description 取 当前缓存中 vehicleId 对应的规则
     * @date 2021/1/29 1:33 下午
     * @params [key, vehicleId]
     */
    public AlarmRule currentVehicleRuleCache(String key, String vehicleId) {
        String cacheRule = ValueUtils.parseString(jedisUtil.hget(key, vehicleId));
        if (StringUtils.isBlank(cacheRule)) return null;

        return JSON.parseObject(cacheRule, AlarmRule.class);
    }

}
